const mongoose = require('mongoose');

const transactionSchema = new mongoose.Schema({
  userId: {
    type: mongoose.Schema.Types.ObjectId,
    ref: 'User',
    required: true
  },
  type: {
    type: String,
    enum: ['earn', 'redeem', 'transfer'],
    required: true
  },
  points: {
    type: Number,
    required: true
  },
  rewardId: String,
  quantity: Number,
  status: {
    type: String,
    enum: ['pending', 'completed', 'failed', 'cancelled'],
    default: 'pending'
  },
  description: String,
  metadata: {
    // 存储额外信息
    source: String,
    category: String,
    partnerId: mongoose.Schema.Types.ObjectId
  }
}, { timestamps: true });

module.exports = mongoose.model('Transaction', transactionSchema); 